package jdwl.hrmgrsys.action;

import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import jdwl.hrmgrsys.pojo.Enterprise;
import jdwl.hrmgrsys.pojo.HR;
import jdwl.hrmgrsys.pojo.core.CommonPara;
import jdwl.hrmgrsys.service.EnterpriseMgrService;
import jdwl.hrmgrsys.service.EnterpriseParamService;

import org.apache.struts2.config.DefaultSettings;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class EnterpriseAction extends PageAction<Enterprise> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Enterprise enterprise;
	private List<CommonPara> enterpriseTypes;
	private HR hr;
	@Resource
	private EnterpriseMgrService service;
	@Resource
	private EnterpriseParamService sysService;

	public String addEnterprise() {
		getEnterprise().setHr(getHr());
		Long tid=getEnterprise().getEnterpriseType().getId();
		if(tid==null){
			addActionError(DefaultSettings.get("enterprise.type.isNull"));
		}
		CommonPara enterpriseType = (CommonPara)sysService.getDao().load(CommonPara.class, tid);
		getEnterprise().setEnterpriseType(enterpriseType);
		service.addEnterprise(getEnterprise());
		return SUCCESS;
	}
	
	public String listEnterprise(){
		LinkedHashMap orderBy = getOrderBy();
		setResult(service.list(Enterprise.class, getPageNo(),getiDisplayLength(), null,
				orderBy));
		return SUCCESS;
	}

	public Enterprise getEnterprise() {
		return enterprise;
	}

	public List<CommonPara> getEnterpriseTypes() {
		return enterpriseTypes;
	}

	public HR getHr() {
		return hr;
	}

	public EnterpriseMgrService getService() {
		return service;
	}

	public EnterpriseParamService getSysService() {
		return sysService;
	}

	public String initAddEnterprise() {
		String code = DefaultSettings.get("enterprise.type.paraname");
		this.enterpriseTypes = sysService.queryCommonParasByType(code);
		return SUCCESS;
	}

	public void setEnterprise(Enterprise enterprise) {
		this.enterprise = enterprise;
	}

	public void setEnterpriseTypes(List<CommonPara> enterprsieTypes) {
		this.enterpriseTypes = enterprsieTypes;
	}

	public void setHr(HR hr) {
		this.hr = hr;
	}

	public void setService(EnterpriseMgrService service) {
		this.service = service;
	}

	public void setSysService(EnterpriseParamService sysService) {
		this.sysService = sysService;
	}

}
